efform_onload = function (){
	var year=$('#inqu_status-0-year',window.parent.document).val();
	var month=$('#inqu_status-0-month',window.parent.document).val();
	$('#inqu_status-0-fdYear').val(year);
	$('#inqu_status-0-fdMonth').val(month);
}; 
button_insert_onclick = function (){
	if (isSelected("ef_grid_r") == 0)return; 
//	efgrid.submitForm( "ef_grid_r", "ZM","ZMCN42","insert",true);
	var info = getSCZXEiInfos("ZMCN42","ef_grid_r");
	if (null != info) {
		EiCommunicator.send("ZMCN42", "validate", info, validate_callback);
	} 
}

button_update_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行修改！"); return;
		}
	}
	var info = getSCZXEiInfos("ZMCN42","ef_grid_r");
	if (null != info) {
		EiCommunicator.send("ZMCN42", "validate", info, validate_callback);
	} 
}

button_delete_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_r", "ZM","ZMCN42","delete",true);
	}); 
}
button_report_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("该记录或有记录已经上报！"); return;
		}
	}
	EFConfirm('你确认要上报吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_r", "ZM","ZMCN42","report",true);
	}); 
}
efgrid_afterAddNewRow = function(grid_id){ 
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();  
	if(grid_id=="ef_grid_r")
	{
		for(var i = 0 ; i < rows.length;i++){
			grid.getBlockData().setCell(rows[i], "fdStatus", "草拟");
			grid.getBlockData().setCell(rows[i], "fdReportTime", getCurrentDate());
			grid.getBlockData().setCell(rows[i], "fdKeyId", "");
		}
	}
}
var validate_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					oper="update";
				}
				efgrid.submitForm( "ef_grid_r", "ZM","ZMCN42",oper,true);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}

button_print_onclick = function() {
	// 取报表参数
	var fdYear = $('#inqu_status-0-fdYear').val();
	var fdMonth = $('#inqu_status-0-fdMonth').val();
	
	var param = [];
	param.YEAR =fdYear;
	param.MONTH=fdMonth;
	var reportEname = "ZM_CN_CCY";
	try {
		previewReport(reportEname,param);
	} catch (e) {
		alert("控件加载失败，请确认控件是否正确安装并将本网站设为信任地址");
	}
}
//ZMCN40从表页签输入煤样编码后带出相关信息
efgrid_onDataCellSaved = function( grid_id, row_index, col_index, cell_value ) 
{
	var grid = efgrid.getGridObject( grid_id ); 
	if( col_index == 6 ||col_index ==12){
        //抽检化验结果
		var fdMyAd=grid.getCellValueByColumnName(row_index, "fdMyAd"); // 原Ad(%)
		var fdMyAd2 = grid.getCellValueByColumnName(row_index, "fdCjAd"); // 抽Ad(%)
		var cha2=calculate(fdMyAd2,fdMyAd).toFixed(2);
		grid.getBlockData().setCell(row_index, "fdCzAd", cha2);
		grid.refreshCell( row_index, 15 , TYPE_DATA );
	}else if(col_index==7||col_index ==13){
		var fdMySt = grid.getCellValueByColumnName(row_index, "fdMySt"); // 抽St,d(%)
		var fdMySt2 = grid.getCellValueByColumnName(row_index, "fdCjSt"); // 抽St,d(%)
		var cha3=calculate(fdMySt2,fdMySt).toFixed(2);
		grid.getBlockData().setCell(row_index, "fdCzSt", cha3);
		grid.refreshCell( row_index, 16 , TYPE_DATA );
	}else if(col_index==8||col_index ==14){
		var fdMyQgr = grid.getCellValueByColumnName(row_index, "fdMyQgr"); // 原Qgr.v.d(MJ/kg)
		var fdCjQgr2 = grid.getCellValueByColumnName(row_index, "fdCjQgr"); // 抽Qgr.v.d(MJ/kg)
		var cha4=calculate(fdCjQgr2,fdMyQgr).toFixed(2);
		grid.getBlockData().setCell(row_index, "fdCzQgr", cha4);
		grid.refreshCell( row_index, 17 , TYPE_DATA );
	}
}
//ZMCN40从表页签输入煤样编码后带出相关信息回调函数
var query_callback= {
		onSuccess: function(eiInfo) { 
			if(eiInfo.getStatus()==-1){
				EFAlert(eiInfo.getMsg());
				//置空所有带出字段值
				  var row_index=eiInfo.get("row_index");
				  var grid = efgrid.getGridObject("ef_grid_r");
				  grid.getBlockData().setCell(row_index, "fdMyMad",0);
				  grid.getBlockData().setCell(row_index, "fdMyAd",0);
				  grid.getBlockData().setCell(row_index, "fdMySt", 0);
				  grid.getBlockData().setCell(row_index, "fdMyQgr", 0);
				  grid.getBlockData().setCell(row_index, "fdCzAd", 0);
				  grid.getBlockData().setCell(row_index, "fdCzSt", 0);
				  grid.getBlockData().setCell(row_index, "fdCzQgr", 0);
				  grid.refreshCell( row_index, 5 , TYPE_DATA );
				  grid.refreshCell( row_index, 6 , TYPE_DATA );
				  grid.refreshCell( row_index, 7 , TYPE_DATA );
				  grid.refreshCell( row_index, 8 , TYPE_DATA );	
				  grid.refreshCell( row_index, 15 , TYPE_DATA );
				  grid.refreshCell( row_index, 16 , TYPE_DATA );
				  grid.refreshCell( row_index, 17 , TYPE_DATA );
				return;
			}
		  var row_index=eiInfo.get("row_index");
		  //原化验结果
		  var grid = efgrid.getGridObject("ef_grid_r");
		  var fdMyMad=eiInfo.getBlock('result').getCell(0,"fdMyMad");
		  var fdMyAd=eiInfo.getBlock('result').getCell(0,"fdMyAd");
		  var fdMySt=eiInfo.getBlock('result').getCell(0,"fdMySt");
		  var fdMyQgrd=eiInfo.getBlock('result').getCell(0,"fdMyQgrd");
		  grid.getBlockData().setCell(row_index, "fdMyMad",fdMyMad );
		  grid.getBlockData().setCell(row_index, "fdMyAd",fdMyAd);
		  grid.getBlockData().setCell(row_index, "fdMySt", fdMySt);
		  grid.getBlockData().setCell(row_index, "fdMyQgr", fdMyQgrd);
		  
		  grid.refreshCell( row_index, 5 , TYPE_DATA );
		  grid.refreshCell( row_index, 6 , TYPE_DATA );
		  grid.refreshCell( row_index, 7 , TYPE_DATA );
		  grid.refreshCell( row_index, 8 , TYPE_DATA );	
		  
            //抽检化验结果
			var fdMyMad2 = grid.getCellValueByColumnName(row_index, "fdCjMad"); // 抽Mad(%)
			var fdMyAd2 = grid.getCellValueByColumnName(row_index, "fdCjAd"); // 抽Ad(%)
			var fdMySt2 = grid.getCellValueByColumnName(row_index, "fdCjSt"); // 抽St,d(%)
			var fdMyQgrd2 = grid.getCellValueByColumnName(row_index, "fdCjQgr"); // 抽Qgr.v.d(MJ/kg)
			// 计算差值：抽检结果-原化验结果                
			var cha2;
			var cha3;
			var cha4;
			cha2=calculate(fdMyAd2,fdMyAd);
			cha3=calculate(fdMySt2,fdMySt);
			cha4=calculate(fdMyQgrd2,fdMyQgrd);
			alert(fdMyQgrd2-fdMyQgrd);
			grid.getBlockData().setCell(row_index, "fdCzAd", cha2);
			grid.getBlockData().setCell(row_index, "fdCzSt", cha3);
			grid.getBlockData().setCell(row_index, "fdCzQgr", cha4);
			
			grid.refreshCell( row_index, 15 , TYPE_DATA );
			grid.refreshCell( row_index, 16 , TYPE_DATA );
			grid.refreshCell( row_index, 17 , TYPE_DATA );
		},
		onFail:function(eMsg)
		{
			EFAlert("根据煤样编码查询化验结果失败，原因："+eMsg); 
		}
	}
